package client;

import command.Command;
import command.concreteCommand.AirConditionerCommand;
import command.concreteCommand.LightOffCommand;
import command.concreteCommand.LightOnCommand;
import command.concreteCommand.MacroCommand;
import invoker.RemoteControl;
import receiver.AirConditioner;
import receiver.Light;

import java.util.Arrays;
import java.util.List;

// 客户端使用
public class SmartHomeDemo {
    public static void main(String[] args) {
        RemoteControl remote = new RemoteControl(3);
        
        // 创建设备
        Light livingRoomLight = new Light("Living Room");
        Light kitchenLight = new Light("Kitchen");
        AirConditioner ac = new AirConditioner();
        
        // 创建命令
        Command livingRoomLightOn = new LightOnCommand(livingRoomLight);
        Command livingRoomLightOff = new LightOffCommand(livingRoomLight);
        Command kitchenLightOn = new LightOnCommand(kitchenLight);
        Command kitchenLightOff = new LightOffCommand(kitchenLight);
        Command acCommand = new AirConditionerCommand(ac);
        
        // 设置遥控器按钮
        remote.setCommand(0, livingRoomLightOn, livingRoomLightOff);
        remote.setCommand(1, kitchenLightOn, kitchenLightOff);
        remote.setCommand(2, acCommand, acCommand);
        
        // 使用遥控器
        System.out.println("=== Testing Remote Control ===");
        remote.pressOnButton(0);  // 打开客厅灯
        remote.pressOnButton(1);  // 打开厨房灯
        remote.pressOnButton(2);  // 打开空调
        
        System.out.println("\n=== Undo Operations ===");
        remote.pressUndoButton(); // 撤销空调
        remote.pressUndoButton(); // 撤销厨房灯
        
        System.out.println("\n=== Macro Command ===");
        // 创建"回家模式"宏命令
        List<Command> homeModeCommands = Arrays.asList(
            livingRoomLightOn,
            kitchenLightOn,
            acCommand
        );
        MacroCommand homeMode = new MacroCommand(homeModeCommands);
        
        homeMode.execute();
        System.out.println("--- Undo home mode ---");
        homeMode.undo();
    }
}